package com.sanpu.kxe.business.card.view;

import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.text.TextPaint;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.card.adapter.MyBankListAdapter;

import butterknife.Bind;

/**
 * Description：我的银行卡列表
 * Created by 薛勇军 on 2018/7/10.
 */
@Route(path = "/repay/RepayCredit")
public class MyBankListActivity extends BaseTitleActivity {

    @Bind(R.id.viewPage)
    ViewPager vViewPage;
    @Bind(R.id.leftTv)
    TextView leftTv;
    @Bind(R.id.rightTv)
    TextView rightTv;
    @Bind(R.id.backLl)
    LinearLayout backLl;

    private MyBankListAdapter mBankListAdapter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_my_bank_list;
    }

    @Override
    protected void initView() {
        super.initView();
        mBankListAdapter = new MyBankListAdapter(getSupportFragmentManager());
        vViewPage.setOffscreenPageLimit(2);
        vViewPage.setAdapter(mBankListAdapter);
        vViewPage.setCurrentItem(0);
    }

    @Override
    protected void setListener() {
        super.setListener();
        backLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        leftTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCreditChecked(0);
                vViewPage.setCurrentItem(0);
            }
        });
        rightTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCreditChecked(1);
                vViewPage.setCurrentItem(1);
            }
        });
        vViewPage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                onCreditChecked(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    /**
     * 按钮状态切换
     */
    private void onCreditChecked(int position) {
        if (position == 0) {
            leftTv.setTextColor(ContextCompat.getColor(mContext, R.color.black));
            leftTv.setTextSize(24);
            TextPaint paint = leftTv.getPaint();
            paint.setFakeBoldText(true);
            rightTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_909090));
            rightTv.setTextSize(18);
            TextPaint paints = rightTv.getPaint();
            paints.setFakeBoldText(false);
        } else {
            leftTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_909090));
            leftTv.setTextSize(18);
            TextPaint paint = leftTv.getPaint();
            paint.setFakeBoldText(false);
            rightTv.setTextColor(ContextCompat.getColor(mContext, R.color.black));
            rightTv.setTextSize(24);
            TextPaint paints = rightTv.getPaint();
            paints.setFakeBoldText(true);
        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    protected boolean hasCommonTitle() {
        return false;
    }
}
